// ignore_for_file: non_constant_identifier_names

import 'package:flutter/material.dart';

import 'custom_text.dart';

class CustomButton extends StatelessWidget {
  final CustomText? text;
  final Axis direction;
  final Widget? customView;
  final Widget? frontWidget;
  final Widget? afterWidget;

  final MainAxisAlignment mainAxisAlignment;
  final CrossAxisAlignment crossAxisAlignment;
  final MainAxisSize mainAxisSize;
  final Color? color;
  final double borderWidth;
  final Color borderColor;
  final double? borderAllRadius;
  final double? height;
  final double? width;
  final Gradient? gradient;
  final VoidCallback? onPressed;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final List<BoxShadow>? boxShadow;
  final BorderRadiusGeometry? borderRadius;

  const CustomButton({
    super.key,
    this.text,
    this.direction = Axis.horizontal,
    this.customView,
    this.frontWidget,
    this.afterWidget,
    this.mainAxisAlignment = MainAxisAlignment.center,
    this.mainAxisSize = MainAxisSize.max,
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.color,
    this.borderWidth = 0,
    this.borderColor = Colors.transparent,
    this.borderAllRadius,
    this.height,
    this.width,
    this.gradient,
    this.onPressed,
    this.padding,
    this.margin,
    this.boxShadow,
    this.borderRadius,
  });

  @override
  Widget build(BuildContext context) {
    List<Widget> childList = [];
    if (customView != null) childList.add(customView!);
    if (frontWidget != null) childList.add(frontWidget!);
    if (text != null) childList.add(text as Widget);
    if (afterWidget != null) childList.add(afterWidget!);

    Widget widget = Flex(
      mainAxisAlignment: mainAxisAlignment,
      crossAxisAlignment: crossAxisAlignment,
      mainAxisSize: mainAxisSize,
      direction: direction,
      children: childList,
    );
    widget = GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onPressed,
      child: Container(
        padding: padding,
        margin: margin,
        height: height,
        width: width,
        decoration: BoxDecoration(
          gradient: gradient,
          boxShadow: boxShadow,
          color: color,
          border: Border.all(width: borderWidth, color: borderColor),
          borderRadius: borderAllRadius != null
              ? BorderRadius.all(Radius.circular(borderAllRadius!))
              : borderRadius,
        ),
        child: widget,
      ),
    );
    return widget;
  }
}
